import json
import os
# #文件操作1
# with open(r"D:\pythonProject2\pythonProject\object_07_FilesDemo.txt", 'r', encoding='utf-8') as f:
#  print(f.readline())
#  a = str(f.readline())#转成字符串
#  a = a.split(' ')
#  print(a)
# data = {
#  "name":a[0],
#  "addres":a[1],
#  "id":a[2]
# }
# print(data)
# #文件操作2
# with open(r"D:\pythonProject2\pythonProject\object_07_FilesDemo.txt", 'r', encoding='utf-8') as f:
#  data_list = f.readline().split()
#  data_dict = {
#   "name": data_list[0],
#   "address": data_list[1],
#   "id": data_list[2]
#  }
# print(data_dict)

# 文件操作3：读写数据
import json
from importlib.metadata import requires

# list_data = []
#
#
# with open(r"D:\pythonProject2\pythonProject\object_07_FilesDemo.txt", 'r', encoding='utf-8') as read_f:
#     for i in read_f.readlines():
#         if "辽宁省" in i:
#             datas = i.split()
#             # 将处理的数据添加到 list_data 中
#             list_data.append({
#                 "name": datas[0],
#                 "address": datas[1],
#                 "id": datas[2]
#             })
# with open(r'D:\pythonProject2\pythonProject\object_07_JsonDemo.json', 'w', encoding='utf-8') as write_f:
#     json.dump(list_data, write_f, ensure_ascii=False, indent=4)

# 文件操作4
# import json
# with open(r"D:\pythonProject2\pythonProject\test_case.log","r",encoding="utf-8") as f:
#     lines =f.readlines()
#     business = {"request": "","response": ""}
#     for i in lines:
#         bus_data = i.split("执行方法:")[1]
#         if "creditApply" in bus_data:
#             if"请求参数:"in bus_data:
#
#
#                 data = bus_data.split("请求参数:")[1]
#                 json_data = json.loads(data)
#                 json_data.update({"params": json.loads(json_data["params"])})
#                 business["request"] = json_data
#
# with open(r'D:\pythonProject2\pythonProject\object_07_JsonDemo.json', 'w', encoding='utf-8') as write_f:
#     json.dump(business, write_f, ensure_ascii=False, indent=2)


# 文件操作6不会
import json
business = ("ggg")
for i in business:
    with open(r"D:\pythonProject2\pythonProject\object_07_JsonDemo.json", 'r', encoding='utf-8') as f:
        lines = f.readlines()
        for line in lines:
            if "请求参数" in line and i in line:
                data = line.split("请求参数: ")[1]